home *** CD-ROM | disk | FTP | other *** search
- DEMANGLE(3C) Last changed: 4-6-99
-
-
- NNAAMMEE
- ddeemm, ddeemmaannggllee - Demangle C++ external names to a readable format
-
- SSYYNNOOPPSSIISS
- ##iinncclluuddee <<ddeemm..hh>>
-
- cccc [_f_l_a_g ...] _f_i_l_e ... --llmmaannggllee [_l_i_b_r_a_r_y ...]
-
- ttyyppeeddeeff ssttrruucctt DDEEMMAARRGG DDEEMMAARRGG;;
- ttyyppeeddeeff ssttrruucctt DDEEMMCCLL DDEEMMCCLL;;
- ttyyppeeddeeff ssttrruucctt DDEEMM DDEEMM;;
-
- iinntt ddeemmaannggllee((ccoonnsstt cchhaarr **iinn,, cchhaarr **oouutt));;
- iinntt ddeemm((cchhaarr **ss,, DDEEMM **pp,, cchhaarr **bbuuff));;
-
- vvooiidd ddeemm__pprriinnttccll((DDEEMMCCLL **pp,, cchhaarr **bbuuff));;
- vvooiidd ddeemm__pprriinnttaarrgg((DDEEMMAARRGG **pp,, cchhaarr **bbuuff,, iinntt ff));;
- vvooiidd ddeemm__pprriinnttaarrgglliisstt((DDEEMMAARRGG **pp,, cchhaarr **bbuuff,, iinntt ssvv));;
- iinntt ddeemm__pprriinntt((DDEEMM **pp,, cchhaarr **bbuuff));;
- vvooiidd ddeemm__pprriinnttffuunncc((DDEEMM **ddpp,, cchhaarr **bbuuff));;
-
- IIMMPPLLEEMMEENNTTAATTIIOONN
- IRIX systems
-
- DDEESSCCRRIIPPTTIIOONN
- ddeemm and ddeemmaannggllee are interfaces for user programs to demangle the
- mangled external names that C++ produces for functions, class members,
- etc.
-
- A description of the C++ mangling scheme is provided in the _A_n_n_o_t_a_t_e_d
- _C++ _R_e_f_e_r_e_n_c_e _M_a_n_u_a_l (ARM).
-
-
- The simplest interface to the library is to call the ddeemmaannggllee(())
- function, as follows:
-
- int ret;
- char inbuf[1024];
- char outbuf[MAXDBUF];
-
- if ((ret = demangle(inbuf, outbuf)) < 0) {
- /* error! */
- }
-
- The ddeemmaannggllee(()) function will return 0 if it successfully demangled the
- name. If the demangle operation fails, the input string (iinnbbuuff) is
- copied to the output buffer (oouuttbbuuff).
-
- To attain a finer level of control over the demangling operation, call
- the ddeemm(()) function as follows:
-
- int ret;
- char inbuf[1024];
- DEM d;
- char sbuf[MAXDBUF];
-
- ret = dem(inbuf, &d, sbuf);
-
- where iinnbbuuff is the input name, dd the data structure that ddeemm(()) fills
- up, and ssbbuuff is used as an internal buffer that the demangler uses to
- allocate this data structure (dd will contain pointers into ssbbuuff).
-
- Note that the first parameter to ddeemm(()) is of type cchhaarr **, not ccoonnsstt
- cchhaarr **:: A call to ddeemm(()) may alter its input.
-
- There is a constant MMAAXXDDBBUUFF defined in dem.h. This is the maximum
- size of buffer required for an unmangled name's data structure.
-
- ddeemm(()) returns -1 if there is an error, otherwise it returns 0.
-
- The <<ddeemm..hh>> include file has comments describing each field in the
- data structures. The data structures are somewhat complicated by the
- need to handle nested types and function arguments which themselves
- are function pointers with their own arguments.
-
- The following functions can be used to format this data structure:
-
- * ddeemm__pprriinntt(()) formats a complete demangled name from the contents of
- the DEM structure.
-
- * ddeemm__pprriinnttccll(()) formats just a class name.
-
- * ddeemm__pprriinnttffuunncc(()) format just a function name.
-
- * ddeemm__pprriinnttaarrgg(()) formats a single function argument.
-
- * ddeemm__pprriinnttaarrgglliisstt(()) formats a complete function argument list.
-
- DDIIAAGGNNOOSSTTIICCSS
- ddeemmaannggllee(()), ddeemm(()), and ddeemm__pprriinntt(()) return 0 if they succeed, and -1 if
- the input name is not a valid mangled name (or if there are any other
- error conditions, like passing in invalid arguments).
-
- EEXXAAMMPPLLEESS
- This particular application reads from standard input and displays the
- class name for each mangled name read, or "(none)" on errors and C
- functions/data.
-
-
- #include <stdio.h>
- #include <dem.h>
-
- main()
- {
- char sbuf[MAXDBUF];
- DEM d;
- int ret;
- char buf[1024];
- char buf2[1024];
-
- while (gets(buf) != NULL) {
- ret = dem(buf, &d, sbuf);
- if (ret || d.cl == NULL) {
- printf("%s --> (none)\n", buf);
- }
- else {
- dem_printcl(d.cl, buf2);
- printf("%s --> %s\n", buf, buf2);
- }
- }
- }
-
- TTYYPPEENNAAMMEESS
- The demangler handles mangled class typenames, whether they are
- simple, nested, or template classes. For example:
-
- A__pt__2_i --> A<int>
-
- __Q2_1A1B --> A::B
-
- LLOOCCAALL VVAARRIIAABBLLEESS
- The demangler also handles local variables of the following form:
-
- __nnnxxx
-
- For example:
-
- __2x --> x
-
- BBUUGGSS AANNDD AAMMBBIIGGUUIITTIIEESS
- 1. "signed" and "volatile" encodings are not handled.
-
- 2. The encoding for nested classes as mentioned in the ARM is handled
- slightly differently in cfront; there is a ""__"" after the digit
- after the ""QQ"".
-
- 3. A nested class starting with ""QQ"" sometimes has the length encoded
- before it; the demangler handles either case.
-
- 4. The ""TTnnnn"" and ""NNnnnnnn"" notations mentioned in the ARM are not fully
- supported. It is assumed that the number of the designated
- argument is less than or equal to 9. So, if you have 11 or more
- arguments, and you want to repeat argument 10 or greater, the
- demangler will reject the encoded name.
-
- 5. All literal arguments to templates are assumed to be ccoonnsstt. For
- example, the non-const literal value 37 is encoded as CCii.
-
- 6. Some compilers will add a gratuitous ""__"" before external names.
-
- 7. The grammar allows class names up to 999 characters. This is
- considered important for handling templates.
-
- GGRRAAMMMMAARR FFOORR EEXXTTEERRNNAALL NNAAMMEESS
- start --> name
-
- ################# COMPLETE NAMES #################
-
- name --> sti | std | ptbl | func | data | vtbl |
- cname3 | local
-
- sti --> "__sti" "__" id
-
- std --> "__std" "__" id
-
- ptbl --> "__ptbl_vec" "__" id
-
- func --> "__op" arg funcpost | id funcpost
-
- funcpost --> "__" funcpost2 | "__" cname funcpost2
-
- funcpost2 --> csv "F" arglist
-
- csv --> "" | "C" | "S" | "V"
-
- data --> id | id "__" cname
-
- vtbl --> "__vtbl" "__" cname
-
- local --> "__" num regid
-
- ################# CLASS NAMES #################
-
- cname --> cname2 | nest
-
- nest --> "Q" digit "_" cnamelist
-
- cnamelist --> cname2 | cnamelist cname2
-
- cname2 --> cnlen cnid
-
- cname3 --> cnid | "__" nest
-
- cnlen --> digit | digit digit | digit digit digit
-
- cnid --> id | id "__pt__" cnlen "_" arglist
-
- ################# ARGUMENT LISTS #################
-
- arglist --> arg | arglist arg
-
- arg --> modlist arg2 | "X" modlist arg2 lit
-
- modlist --> mod | modlist mod
-
- mod --> "" | "U" | "C" | "V" | "S" | "P" | "R" |
- arr | mptr
-
- arr --> "A" num "_"
-
- mptr --> "M" cname
-
- arg2 --> fund | cname | funcp | repeat1 | repeat2
-
- fund --> "v" | "c" | "s" | "i" | "l" | "f" |
- "d" | "r" | "e"
-
- funcp --> "F" arglist "_" arg
-
- repeat1 --> "T" digit | "T" digit digit
-
- repeat2 --> "N" digit digit | "N" digit digit digit
-
- lit --> litnum | zero | litmptr | cnlen id | sptr
-
- litnum --> "L" digit lnum | "L" digit digit "_" lnum
-
- litmptr --> "LM" num "_" litnum "_" cnlen id
-
- lnum --> num | "n" num
-
- sptr --> cnlen id "__" cname
-
- zero --> 0
-
- ################# LOW LEVEL STUFF #################
-
- digit --> 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
-
- id --> special | regid
-
- special --> "__ct" | "__pp" # etc.
-
- regid --> letter | letter restid
-
- restid --> letter | digit | restid letter |
- restid digit
-
- letter --> "A"-"Z" | "a" - "z" | "_"
-
- num --> digit | num digit
-
- SSEEEE AALLSSOO
- This man page is available only online.
-